home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / dump_song.c < prev    next >
C/C++ Source or Header  |  1995-03-06  |  4KB  |  197 lines

  1. /* dump_song.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: dump_song.c,v 4.16 1995/03/06 23:36:13 espie Exp espie $
  6.  * $Log: dump_song.c,v $
  7.  * Revision 4.16  1995/03/06  23:36:13  espie
  8.  * Proper color patch.
  9.  *
  10.  * Revision 4.15  1995/03/03  14:23:51  espie
  11.  * Color fixed (mostly).
  12.  *
  13.  * Revision 4.14  1995/02/21  21:13:16  espie
  14.  * Cleaned up source. Moved minor pieces of code around.
  15.  *
  16.  * Revision 4.13  1995/02/21  17:54:32  espie
  17.  * Internal problem: buggy RCS. Fixed logs.
  18.  *
  19.  * Revision 4.11  1995/02/20  22:28:50  espie
  20.  * color
  21.  *
  22.  * Revision 4.8  1995/02/06  14:50:47  espie
  23.  * Changed sample_info.
  24.  *
  25.  * Revision 4.7  1995/02/01  20:41:45  espie
  26.  * Added color.
  27.  *
  28.  * Revision 4.6  1995/02/01  16:39:04  espie
  29.  * Includes moved to defs.h
  30.  *
  31.  * Revision 4.0  1994/01/11  17:46:01  espie
  32.  * Use virtual windows.
  33.  * No more call to run_in_fg(), use begin_info result instead.
  34.  * Added instrument name as shown per display.c.
  35.  * Use info facility.
  36.  * Amiga support.
  37.  * Very small bug with volume (Lawrence).
  38.  * Added finetune display.
  39.  * Added bg/fg test.
  40.  */
  41.  
  42. #include "defs.h"
  43.  
  44. #include <ctype.h>
  45.  
  46. #include "song.h"
  47. #include "extern.h"
  48. #include "channel.h"
  49. #include "prefs.h"
  50.  
  51. ID("$Id: dump_song.c,v 4.16 1995/03/06 23:36:13 espie Exp espie $")
  52.  
  53. LOCAL void *handle = 0;
  54. LOCAL char buffer[80];
  55.  
  56. extern char instname[];    /* from display.c */
  57.  
  58.  
  59.  
  60. /***
  61.  ***    dump_block/dump_song:
  62.  ***        show most of the readable info concerning a module on the screen
  63.  ***/
  64.  
  65. /* THIS NEED SOME UPDATING (FIXED VALUE BLOCK_LENGTH/NUMBER_TRACKS) */
  66. LOCAL void dump_block(b)
  67. struct block *b;
  68.    {
  69.    int i, j;
  70.  
  71.    for (i = 0; i < BLOCK_LENGTH; i++)
  72.       {
  73.       for (j = 0; j < NUMBER_TRACKS; j++)
  74.          {
  75.          sprintf(buffer,"%8d%5d%2d%4d", b->e[j][i].sample_number,
  76.             b->e[j][i].pitch, b->e[j][i].effect,
  77.             b->e[j][i].parameters);
  78.          infos(handle, buffer);
  79.          }
  80.       info(handle, "");
  81.       }
  82.    }
  83.  
  84. /* make_readable(s):
  85.  * transform s into a readable string 
  86.  */
  87. LOCAL void make_readable(s)
  88. char *s;
  89.    {
  90.    char *t, *orig;
  91.  
  92.    if (!s)
  93.       return;
  94.  
  95.    orig = s;
  96.    t = s;
  97.  
  98.       /* get rid of the st-xx: junk */
  99.    if (strncmp(s, "st-", 3) == 0 || strncmp(s, "ST-", 3) == 0)
  100.       {
  101.       if (isdigit(s[3]) && isdigit(s[4]) && s[5] == ':')
  102.          s += 6;
  103.       }
  104.    while (*s)
  105.       {
  106.       if (isprint(*s))
  107.          *t++ = *s;
  108.       s++;
  109.       }
  110.    *t = '\0';
  111.    while (t != orig && isspace(t[-1]))
  112.       *--t = '\0';
  113.    }
  114.  
  115. void dump_song(song)
  116. struct song *song;
  117.    {
  118.    int i, j;
  119.    int maxlen;
  120.    static char dummy[1];
  121.  
  122.    
  123.    handle = begin_info(song->title);
  124.    if (!handle)
  125.       return;
  126.  
  127.    dummy[0] = '\0';
  128.    maxlen = 0;
  129.    for (i = 1; i < song->ninstr; i++)
  130.       {
  131.         if (song->samples[i])
  132.             {
  133.             if (!song->samples[i]->name)
  134.                 song->samples[i]->name = dummy;
  135.             make_readable(song->samples[i]->name);
  136.             if (maxlen < strlen(song->samples[i]->name))
  137.                 maxlen = strlen(song->samples[i]->name);
  138.             }
  139.       }
  140.    for (i = 1; i < song->ninstr; i++)
  141.       {
  142.         if (song->samples[i]) 
  143.             {
  144.             if (song->samples[i]->start || strlen(song->samples[i]->name) > 2)
  145.                 {
  146.                 static char s[15];
  147.                 char *base = s;
  148.                 
  149.                 if (get_pref_scalar(PREF_COLOR))
  150.                     {        
  151.                     base = write_color(base, song->samples[i]->color);
  152.                     }
  153.                 *base++ = instname[i];
  154.                 *base++ = ' ';
  155.                 *base++ = 0;
  156.                 infos(handle, s);
  157.                 infos(handle, song->samples[i]->name);
  158.                 for (j = strlen(song->samples[i]->name); j < maxlen + 2; j++)
  159.                     infos(handle, " ");
  160.                 if (song->samples[i]->start)
  161.                     {
  162.                     sprintf(buffer, "%5d", song->samples[i]->length);
  163.                     infos(handle, buffer);
  164.                     if (song->samples[i]->rp_length > 2)
  165.                         {
  166.                         sprintf(buffer, "(%5d %5d)", 
  167.                             song->samples[i]->rp_offset, 
  168.                             song->samples[i]->rp_length);
  169.                         infos(handle, buffer);
  170.                         }
  171.                     else
  172.                         infos(handle, "             ");
  173.                     if (song->samples[i]->volume != MAX_VOLUME)
  174.                         {
  175.                         sprintf(buffer, "%3d", song->samples[i]->volume);
  176.                         infos(handle, buffer);
  177.                         }
  178.                     else 
  179.                         infos(handle, "   ");
  180.                     if (song->samples[i]->finetune)
  181.                         {
  182.                         sprintf(buffer, "%3d", song->samples[i]->finetune);
  183.                         infos(handle, buffer);
  184.                         }
  185.                     }
  186.                 base = s;
  187.                 if (get_pref_scalar(PREF_COLOR))
  188.                     base = write_color(base, 0);
  189.                 *base = 0;
  190.                 info(handle, s);
  191.                 }
  192.             }
  193.       }
  194.    end_info(handle);
  195.    handle = 0;
  196.    }
  197.